package com.yincb;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.SQLException;

public class Mytest {

    public static void main(String[] args) throws SQLException {

        ClassPathXmlApplicationContext applicationContext
                = new ClassPathXmlApplicationContext("applicationContext.xml");

//        DruidDataSource dataSource = applicationContext.getBean("dataSource", DruidDataSource.class);
//        System.out.println(dataSource);
//        System.out.println(dataSource.getConnection());

        JdbcTemplate jdbcTemplate = applicationContext.getBean("jdbcTemplate", JdbcTemplate.class);

        System.out.println(jdbcTemplate);
        String sql = "insert into emp(empno,ename) values(?,?)";

//        int zhangsan = jdbcTemplate.update(sql, "11", "zhangsan");
//        System.out.println(zhangsan);

//        ArrayList<Object[]> list = new ArrayList<>();
//        list.add(new Object[]{"1","zhangsan1"});
//        list.add(new Object[]{"2","zhangsan2"});
//        list.add(new Object[]{"3","zhangsan3"});
//        list.add(new Object[]{"4","zhangsan4"});
//        list.add(new Object[]{"5","zhangsan5"});
//        int[] ints = jdbcTemplate.batchUpdate(sql, list);
//        System.out.println(ints);

//        String sql2 = "select * from emp where empno = ?";
//        List<Emp> query = jdbcTemplate.query(sql2, new BeanPropertyRowMapper<>(Emp.class), "11");
//        System.out.println(query);

//        String sql3 = "select * from emp";
//        List<Emp> list = jdbcTemplate.query(sql3, new BeanPropertyRowMapper<>(Emp.class));
//        for (Emp e :
//                list) {
//            System.out.println(e);
//        }

        String sql3 = "select max(empno) from emp";
        Double aDouble = jdbcTemplate.queryForObject(sql3, Double.class);
        System.out.println(aDouble);
    }



}
